<?php
class videoFetcher{
	public static function get_thumbnail($video_type, $video_id){
		if($video_id=='')return '';
		
		$delegate = create_function('$id','return videoFetcher::get_'.$video_type.'_thumbnail($id);');
		return $delegate($video_id);
	}
	
	public static function get_youku_thumbnail($video_id){
		$url = "http://v.youku.com/v_show/id_{$video_id}.html";
		$contents = file_get_contents($url);
		preg_match_all('/id=\"download\" href=\"(.*)\|\">/U',$contents,$m);
		if(isset($m)&&!empty($m[1])){
			$m_arr = explode("|",$m[1][0]);
		}
		return $m_arr[8];
	}
	public static function get_tudou_thumbnail($video_id){
		$url = "http://www.tudou.com/programs/view/{$video_id}/";
		$contents = file_get_contents($url);
		preg_match_all('/<span class=\"s_pic\">(.*)<\/span>/U',$contents,$m);
		if(isset($m)&&!empty($m[1])){
			$m_arr = explode("|",$m[1][0]);
		}
		return $m_arr[0];
	}
	public static function get_ku6_thumbnail($video_id){
	    $url = "http://v.ku6.com/show/{$video_id}.html";
		    $contents = file_get_contents($url);
		    preg_match_all('/<span class=\"s_pic\">(.*)<\/span>/U',$contents,$m);
		    if(isset($m)&&!empty($m[1])){
			    $m_arr = explode("|",$m[1][0]);
		    }
		    return $m_arr[0];
	}
	public static function get_56_thumbnail($video_id){
	    $url = "http://www.56.com/u70/v_{$video_id}.html";
		    $contents = file_get_contents($url);
		    preg_match_all('/"img":"(.*?) "/U',$contents,$m);
		    if(isset($m)&&!empty($m[1])){
			    $m_arr = explode("|",$m[1][0]);
		    }
		    return str_replace('\\','', $m_arr[0]);
	}
	
	public static function get_joy_thumbnail($video_id){
	    $url = "http://you.joy.cn/video/{$video_id}.htm";
		    $contents = file_get_contents($url);
		    preg_match_all('/Cover:\"(.*?)\",CreateTime/U',$contents,$m);
		    if(isset($m)&&!empty($m[1])){
			    $m_arr = explode("|",$m[1][0]);
		    }
		    return $m_arr[0];
	}
}
?>
